package com.sortingalgorithm;

import java.util.Arrays;

public class InsertSort {
    public static void main(String[] args) {
        int[] arr = {1,3,6,7,2,54,54,4,-1,6,-3};
        insertSort(arr);
        System.out.println(Arrays.toString(arr));
    }

    public static void insertSort(int [ ] arr){
        if(arr == null || arr.length < 2){
            return;
        }
        int len = arr.length;
        for(int i = 1;i < len;i++){
            int j = i;
            int temp = arr[j];
            while (j > 0 && arr[j - 1] > temp){
                arr[j] = arr[j - 1];
                j--;
            }
            arr[j] = temp;
        }
    }
}
